<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2.新浪下拉菜单</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .nav {
            width: 350px;
            margin: 100px auto;
            /* border: 1px solid red; */
            /* overflow: hidden; */
        }

        .clearfix::before,
        .clearfix::after {
            content: '';
            display: table;
            clear: both;
        }

        /* 子元素浮动，解决父元素高度塌陷问题 */

        .nav>li {
            /* 要明确是.nav 的子元素li  而不是所有后代元素li */
            float: left;
            font-size: 12px;
            color: #4c4c4c;
            position: relative;

        }

        .nav>li a {
            line-height: 43px;
            padding: 12px 25px;
            /* 使用内边距 是为了使a元素hover的时候增加面积  如果用的是padding 则a元素hover时只有文字变色*/
            text-decoration: none;
            color: #4c4c4c;
            /* background-color: rgb(252,252,252,); */

        }

        .nav>li a:hover {
            background-color: rgb(237, 238, 240);
            color: rgb(255, 132, 0);

        }

        li {
            list-style-type: none;
        }

        .nav>li>ul {
            display: none;
            position: absolute;
            width: 100%;
            /* left: 25px; */
            top: 42px;
            border-left: 1px solid rgb(254, 204, 91);
            border-right: 1px solid rgb(254, 204, 91);

        }



        .nav>li>ul li {

            text-align: center;
            line-height: 32px;
            border-bottom: 1px solid rgb(254, 204, 91);

        }
        .nav>li>ul a:hover{
            color: rgb( 255,132,0);
        }
        .nav>li>ul li:hover{
            background-color: rgb(255,245,218);
        }
    </style>
</head>

<body>
    <ul class="nav clearfix">
        <li>
            <a href="#">登录</a>
            <ul>
                <li>私信</li>
                <li>评论</li>
                <li>@我</li>
            </ul>
        </li>
        <li>
            <a href="#">微博</a>
            <ul>
                <li>私信1</li>
                <li>评论2</li>
                <li>@我3</li>
            </ul>
        </li>
        <li>
            <a href="#">博客</a>
            <ul>
                <li>博客评论</li>
                <li>未读提醒</li>

            </ul>
        </li>
        <li>
            <a href="#">邮箱</a>
            <ul>
                <li>免费邮箱</li>
                <li>VIP邮箱</li>
                <li>企业邮箱</li>
                <li>邮箱客户端</li>
            </ul>
        </li>

    </ul>

    <script>
        var lis = document.querySelector('.nav').children;
        console.log(lis);
        for (let index = 0; index < lis.length; index++) {
            lis[index].onmouseover = function () {
             
                this.children[1].style.display = 'block';
            }
            lis[index].onmouseout=function(){
                lis[index].children[1].style.display = 'none';
            }

        }
    </script>

</body>

</html>